package com.itfitness.mchart.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hyphenate.chat.EMClient;
import com.itfitness.mchart.R;
import com.itfitness.mchart.activity.LoginActivity;
import com.itfitness.mchart.factory.DialogFactory;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @ProjectName: MChart
 * @Package: com.itfitness.mchart.fragment
 * @ClassName: MineFragment
 * @Description: java类作用描述 ：
 * @Author: 作者名：lml
 * @CreateDate: 2019/4/24 9:34
 * @UpdateUser: 更新者：
 * @UpdateDate: 2019/4/24 9:34
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class MineFragment extends BaseFragment {
    @BindView(R.id.fragment_mine_tv_username)
    TextView fragmentMineTvUsername;
    @BindView(R.id.fragment_mine_item_logout)
    RelativeLayout fragmentMineItemLogout;

    @Override
    protected int LayoutRes() {
        return R.layout.fragment_mine;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this, view);
        fragmentMineTvUsername.setText(EMClient.getInstance().getCurrentUser());
    }

    @OnClick({R.id.fragment_mine_tv_username, R.id.fragment_mine_item_logout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fragment_mine_tv_username:
                break;
            case R.id.fragment_mine_item_logout:
                DialogFactory.createDefaultDialog(getContext(), "是否退出登录？", "确定", "取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        EMClient.getInstance().logout(false);
                        getActivity().finish();
                        gotoActivity(LoginActivity.class);
                    }
                }, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
                break;
        }
    }
}
